package com.atilim.cargo.business;

import javax.ejb.Stateless;
import javax.inject.Inject;

import com.atilim.cargo.model.Cargo;
import com.atilim.cargo.model.Customer;
import com.atilim.cargo.model.User;
import com.atilim.cargo.model.Vechile;

//Kullanıcı araç gibi bilgilerin doğruluklarını kontrol eden iş sınıfı
@Stateless
public class ValidationBean extends BaseBean {

	@Inject
	AdministrationBean administrationBean;
	
	
	public boolean validateUser (User user) {
		if (user.getName() == null || user.getName() == ""
				|| user.getPassword() == null || user.getPassword() == ""
				|| user.getUsername() == null || user.getUsername() == ""
				|| user.getSurname() == null || user.getSurname() == ""
				|| (user.getType() != User.USER_TYPE_ADMIN && user.getType() != User.USER_TYPE_CUSTOMER && user.getType() != User.USER_TYPE_WORKER)) {
			return false;
		}
		
		return true;
	}
	
	public boolean validateVechile (Vechile vechile) {
		
		//TODO aylin araç doğruluğunu sağlayın
		
		return true;
	}

	public boolean validateCustomer (Customer customer) {
		
		if (customer.getName() == null || customer.getName().equals("")
				|| customer.getSurname() == null || "".equals(customer.getSurname())
				|| customer.getTckn() == null || "".equals(customer.getTckn()) || customer.getTckn().length() != 11) {
			return false;
		}
		
		return true;
	}
	
	public boolean validateCargo (Cargo cargo) {
		
		Customer customer = administrationBean.getCustomer(cargo.getCustomerId());
		if (customer == null) {
			return false;
		}
		
		//TODO diğerlerini ekle
		
		return true;
	}
	
}
